package com.ruoyi.web.controller.monitor;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.monitor.domain.BusWaterAutomonitorDaydata;
import com.ruoyi.monitor.domain.BusWaterAutomonitorHourdata;
import com.ruoyi.monitor.domain.GetWaterAutomonitorParam;
import com.ruoyi.monitor.service.IBusWaterAutomonitorDaydataService;
import com.ruoyi.monitor.service.IBusWaterAutomonitorHourdataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 水监测小时数据Controller
 * 
 * @author maliang
 * @date 2025-07-31
 */
@RestController
@RequestMapping("/monitor/autohourdata")
public class BusWaterAutomonitorHourdataController extends BaseController
{
    @Autowired
    private IBusWaterAutomonitorHourdataService busWaterAutomonitorHourdataService;
    @Autowired
    private IBusWaterAutomonitorDaydataService busWaterAutomonitorDaydataService;

    /**
     * 查询水监测小时数据列表
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autohourdata:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusWaterAutomonitorHourdata busWaterAutomonitorHourdata)
    {
        startPage();
        List<BusWaterAutomonitorHourdata> list = busWaterAutomonitorHourdataService.selectBusWaterAutomonitorHourdataList(busWaterAutomonitorHourdata);
        return getDataTable(list);
    }

    /**
     * 导出水监测小时数据列表
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autohourdata:export')")
    @Log(title = "水监测小时数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusWaterAutomonitorHourdata busWaterAutomonitorHourdata)
    {
        List<BusWaterAutomonitorHourdata> list = busWaterAutomonitorHourdataService.selectBusWaterAutomonitorHourdataList(busWaterAutomonitorHourdata);
        ExcelUtil<BusWaterAutomonitorHourdata> util = new ExcelUtil<BusWaterAutomonitorHourdata>(BusWaterAutomonitorHourdata.class);
        util.exportExcel(response, list, "水监测小时数据数据");
    }

    /**
     * 获取水监测小时数据详细信息
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autohourdata:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(busWaterAutomonitorHourdataService.selectBusWaterAutomonitorHourdataById(id));
    }

    /**
     * 新增水监测小时数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autohourdata:add')")
    @Log(title = "水监测小时数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusWaterAutomonitorHourdata busWaterAutomonitorHourdata)
    {
        return toAjax(busWaterAutomonitorHourdataService.insertBusWaterAutomonitorHourdata(busWaterAutomonitorHourdata));
    }

    /**
     * 修改水监测小时数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autohourdata:edit')")
    @Log(title = "水监测小时数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusWaterAutomonitorHourdata busWaterAutomonitorHourdata)
    {
        return toAjax(busWaterAutomonitorHourdataService.updateBusWaterAutomonitorHourdata(busWaterAutomonitorHourdata));
    }

    /**
     * 删除水监测小时数据
     */
    //@PreAuthorize("@ss.hasPermi('monitor:autohourdata:remove')")
    @Log(title = "水监测小时数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(busWaterAutomonitorHourdataService.deleteBusWaterAutomonitorHourdataByIds(ids));
    }

    /**
     * 查询时间段断面项目水监测数据
     * @param getWaterAutomonitorParam
     * @return
     */
    @PostMapping("/itemlist")
    public AjaxResult itemList(@RequestBody GetWaterAutomonitorParam getWaterAutomonitorParam)
    {
        if (StringUtils.isNotEmpty(getWaterAutomonitorParam.getDatatype()) && Objects.equals(getWaterAutomonitorParam.getDatatype(), "0"))
        {
            List<BusWaterAutomonitorHourdata> list = busWaterAutomonitorHourdataService.selectBusWaterAutomonitorHourdataItemList(getWaterAutomonitorParam);
            return AjaxResult.success(list);
        }
        else if (StringUtils.isNotEmpty(getWaterAutomonitorParam.getDatatype()) && Objects.equals(getWaterAutomonitorParam.getDatatype(), "1"))
        {
            List<BusWaterAutomonitorDaydata> list = busWaterAutomonitorDaydataService.selectBusWaterAutomonitorDaydataItemList(getWaterAutomonitorParam);
            return AjaxResult.success(list);
        }
        return AjaxResult.success(null);
    }

    /**
     * 日报
     * @param id
     * @param day
     * @return
     */
    @GetMapping("/dailyReport")
    public AjaxResult dailyReport(String id,String day){
        return AjaxResult.success(busWaterAutomonitorHourdataService.dailyReport(id,day));
    }

    /**
     * 主要污染物占比(日)
     * @return
     */
    @GetMapping("/dayPollutantsPropor")
    public AjaxResult dayPollutantsPropor(String startTime,String endTime,String countyCode,String riverId){
        return AjaxResult.success(busWaterAutomonitorHourdataService.dayPollutantsPropor(startTime,endTime,countyCode,riverId));
    }

    /**
     * 主要污染物占比（月）
     * @return
     */
    @GetMapping("/monthPollutantsPropor")
    public AjaxResult monthPollutantsPropor(String startTime,String endTime,String countyCode,String riverId){
        return AjaxResult.success(busWaterAutomonitorHourdataService.monthPollutantsPropor(startTime,endTime,countyCode,riverId));
    }
}
